<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Iterator Based Generator API</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Spirit 2.59">
<link rel="up" href="../generate_api.html" title="Generator API">
<link rel="prev" href="../generate_api.html" title="Generator API">
<link rel="next" href="stream_api.html" title="Stream Based Generator API">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../generate_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generate_api.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="stream_api.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="spirit.karma.reference.generate_api.iterator_api"></a><a class="link" href="iterator_api.html" title="Iterator Based Generator API">Iterator
          Based Generator API</a>
</h5></div></div></div>
<h6>
<a name="spirit.karma.reference.generate_api.iterator_api.h0"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.iterator_api.description"></a></span><a class="link" href="iterator_api.html#spirit.karma.reference.generate_api.iterator_api.description">Description</a>
          </h6>
<p>
            The library provides a couple of free functions to make generating a
            snap. These generator functions have two forms. The first form, <code class="computeroutput"><span class="identifier">generate</span></code>, concatenates the output generated
            by the involved components without inserting any output in between. The
            second <code class="computeroutput"><span class="identifier">generate_delimited</span></code>
            intersperses the output generated by the involved components using the
            given delimiter generator. Both versions can take in attributes by (constant)
            reference that hold the attribute values to output.
          </p>
<h6>
<a name="spirit.karma.reference.generate_api.iterator_api.h1"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.iterator_api.header"></a></span><a class="link" href="iterator_api.html#spirit.karma.reference.generate_api.iterator_api.header">Header</a>
          </h6>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/generate.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_generate</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            For variadic attributes:
          </p>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/generate_attr.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_generate_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            The variadic attributes version of the API allows one or more attributes
            to be passed into the <code class="computeroutput"><span class="identifier">generate</span></code>
            functions. The functions taking two or more attributes are usable when
            the generator expression is a <a class="link" href="../operator/sequence.html" title="Sequence Generator (a &lt;&lt; b)">Sequence
            (<code class="computeroutput"><span class="special">&lt;&lt;</span></code>)</a> only.
            In this case each of the attributes passed have to match the corresponding
            part of the sequence.
          </p>
<p>
            For the API functions deducing the correct (matching) generator type
            from the supplied attribute type:
          </p>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/detail/generate_auto.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_generate_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
          </p>
<h6>
<a name="spirit.karma.reference.generate_api.iterator_api.h2"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.iterator_api.namespace"></a></span><a class="link" href="iterator_api.html#spirit.karma.reference.generate_api.iterator_api.namespace">Namespace</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                    <p>
                      Name
                    </p>
                  </th></tr></thead>
<tbody>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">generate</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">generate_delimited</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">predelimit</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span></code>
                    </p>
                  </td></tr>
</tbody>
</table></div>
<h6>
<a name="spirit.karma.reference.generate_api.iterator_api.h3"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.iterator_api.synopsis"></a></span><a class="link" href="iterator_api.html#spirit.karma.reference.generate_api.iterator_api.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">karma</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate_delimited</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">delimiter</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span> <span class="special">=</span> <span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate_delimited</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">delimiter</span>
      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate_delimited</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">delimiter</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span>
      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
<span class="special">}}}</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              Starting with <a href="http://boost-spirit.com" target="_top">Spirit</a> V2.5
              (distributed with Boost V1.47) the placeholder <code class="computeroutput"><span class="identifier">_val</span></code>
              can be used in semantic actions attached to top level generator components.
              In this case <code class="computeroutput"><span class="identifier">_val</span></code> refers
              to the supplied attribute as a whole. For API functions taking more
              than one attribute argument <code class="computeroutput"><span class="identifier">_val</span></code>
              will refer to a Fusion vector or references to the attributes.
            </p></td></tr>
</table></div>
<p>
            <span class="emphasis"><em>Spirit.Karma</em></span> generator API functions based on the
            automatic creation of the matching generator type:
          </p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">karma</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate_delimited</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">delimiter</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span> <span class="special">=</span> <span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">generate</span><span class="special">(</span>
        <span class="identifier">OutputIterator</span><span class="special">&amp;</span> <span class="identifier">sink</span>
      <span class="special">,</span> <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">);</span>
<span class="special">}}}</span>
</pre>
<p>
            All functions above return <code class="computeroutput"><span class="keyword">true</span></code>
            if none of the involved generator components failed, and <code class="computeroutput"><span class="keyword">false</span></code> otherwise. If during the process
            of the output generation the underlying output stream reports an error,
            the return value will be <code class="computeroutput"><span class="keyword">false</span></code>
            as well.
          </p>
<p>
            The maximum number of supported arguments is limited by the preprocessor
            constant <code class="computeroutput"><span class="identifier">SPIRIT_ARGUMENTS_LIMIT</span></code>.
            This constant defaults to the value defined by the preprocessor constant
            <code class="computeroutput"><span class="identifier">PHOENIX_LIMIT</span></code> (which
            in turn defaults to <code class="computeroutput"><span class="number">10</span></code>).
          </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              The variadic functions with two or more attributes internally combine
              (constant) references to all passed attributes into a <code class="computeroutput"><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">vector</span></code> and forward this as a combined
              attribute to the corresponding function taking one attribute.
            </p></td></tr>
</table></div>
<p>
            The <code class="computeroutput"><span class="identifier">generate_delimited</span></code>
            functions not taking an explicit <code class="computeroutput"><span class="identifier">delimit_flag</span></code>
            as one of their arguments don't invoke the passed delimiter before starting
            to generate output from the generator expression. This can be enabled
            by using the other version of that function while passing <code class="computeroutput"><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">predelimit</span></code> to the corresponding argument.
          </p>
<h6>
<a name="spirit.karma.reference.generate_api.iterator_api.h4"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.iterator_api.template_parameters"></a></span><a class="link" href="iterator_api.html#spirit.karma.reference.generate_api.iterator_api.template_parameters">Template
            parameters</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Parameter
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">OutputIterator</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <a href="http://en.cppreference.com/w/cpp/named_req/OutputIterator" target="_top"><code class="computeroutput"><span class="identifier">OutputIterator</span></code></a> receiving
                      the generated output.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Expr</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      An expression that can be converted to a Karma generator.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Delimiter</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generator used to delimit the output of the expression components.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Attr</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      An attribute type utilized to create the corresponding generator
                      type from.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Attr1</span></code>, <code class="computeroutput"><span class="identifier">Attr2</span></code>, ..., <code class="computeroutput"><span class="identifier">AttrN</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      One or more attributes.
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../generate_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generate_api.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="stream_api.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
